﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using System.Net;
using System.Net.Sockets;

namespace udp_camera
{


    public class UdpImageServer
    {
        private int port;
        private UdpClient udpServer;
        private IPEndPoint udp_ep;
        Thread receiveThread;
        ASCIIEncoding ascii;

        public UdpImageServer(int port)
        {
            this.port = port; ;
        }

        public void startListening()
        {
            ascii = new ASCIIEncoding();
            byte[] data = new byte[500];
            udp_ep = new IPEndPoint(IPAddress.Any, this.port);
            udpServer = new UdpClient(this.port);
            while (true)
            {
                data = udpServer.Receive(ref udp_ep);
                Console.WriteLine(ascii.GetString(data,0,data.Length));
            }
        }





    }
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            UdpImageServer udpServer = new UdpImageServer(5000);
            Thread udpServerThread = new Thread(new ThreadStart(udpServer.startListening));
            udpServerThread.Start();
            

            for(;;);
        }



    }
}
